/**
 * Copyright 2008 Mathias Doenitz, http://lis.to/
 *
 * This file is part of the lis.to java desktop client. The lis.to java desktop client is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * The lis.to java desktop client is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with the lis.to java desktop client.
 * If not, see http://www.gnu.org/licenses/
 */

package listo.client;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import listo.utils.FileUtils2;
import listo.utils.MiscUtils;
import listo.utils.logging.Log;
import listo.utils.reflection.Reflector;

import java.util.Properties;

@SuppressWarnings({"UnusedDeclaration"})
@Singleton
public class AppConfig {

    private String version;
    private String buildTime;

    private int windowDefaultPosX;
    private int windowDefaultPosY;
    private int windowDefaultSizeX;
    private int windowDefaultSizeY;
    private int windowDefaultSplitX;
    private int windowMinSizeX;
    private int windowMinSizeY;
    private int windowMinSplitX;
    private WindowState.CompletionView defaultCompletionView;
    private WindowState.TaskDialogState defaultTaskDialogState;

    private int taskDialogMinWidth;
    private int taskDialogDefaultWidth;

    private int reminderCheck;
    private int autoRemover;
    private int autoRemoverInitial;
    private int onCancelReminderPause;

    private int tasklistRefresh;

    private int executorsTerminationTimeout;

    private String aboutLink;

    @Inject
    public AppConfig(Log log, Reflector reflector, @Named("CONFIG_RESOURCE")String configResource) {
        log.info("Loading application config from resource %1$s", configResource);
        String configText = FileUtils2.readAllTextFromResource(configResource);
        Properties properties = MiscUtils.deserialize(configText);
        if (properties == null) throw new RuntimeException("Could not load application config");

        try {
            reflector.f(this).loadFromProperties(properties);
        }
        catch (Exception e) {
            throw new RuntimeException("Could not load application config", e);
        }
    }

    public String getVersion() {
        return version;
    }

    public String getBuildTime() {
        return buildTime;
    }

    public int getWindowDefaultPosX() {
        return windowDefaultPosX;
    }

    public int getWindowDefaultPosY() {
        return windowDefaultPosY;
    }

    public int getWindowDefaultSizeX() {
        return windowDefaultSizeX;
    }

    public int getWindowDefaultSizeY() {
        return windowDefaultSizeY;
    }

    public int getWindowDefaultSplitX() {
        return windowDefaultSplitX;
    }

    public int getWindowMinSizeX() {
        return windowMinSizeX;
    }

    public int getWindowMinSizeY() {
        return windowMinSizeY;
    }

    public int getWindowMinSplitX() {
        return windowMinSplitX;
    }

    public WindowState.CompletionView getDefaultCompletionView() {
        return defaultCompletionView;
    }

    public WindowState.TaskDialogState getDefaultTaskDialogState() {
        return defaultTaskDialogState;
    }

    public int getTaskDialogMinWidth() {
        return taskDialogMinWidth;
    }

    public int getTaskDialogDefaultWidth() {
        return taskDialogDefaultWidth;
    }

    public int getReminderCheck() {
        return reminderCheck;
    }

    public int getAutoRemover() {
        return autoRemover;
    }

    public int getAutoRemoverInitial() {
        return autoRemoverInitial;
    }

    public int getOnCancelReminderPause() {
        return onCancelReminderPause;
    }

    public int getTasklistRefresh() {
        return tasklistRefresh;
    }

    public int getExecutorsTerminationTimeout() {
        return executorsTerminationTimeout;
    }

    public String getAboutLink() {
        return aboutLink;
    }
}